package com.ys168.gam.download;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Jason Krebs
 * @since 2015年6月11日
 */
public class DownloadEventSource {

    private List<IDownloadListener> downloadListeners;

    public DownloadEventSource() {
        downloadListeners = new ArrayList<IDownloadListener>();
    }

    void activeAllDownloadFinishedEvent() {
        for (IDownloadListener listener : downloadListeners) {
            listener.onAllDownloadFinished();
        }
    }

    void activeDownloadFinishedEvent(DownloadEvent event) {
        for (IDownloadListener listener : downloadListeners) {
            listener.onDownloadFinished(event);
        }
    }

    void activeDownloadingEvent(DownloadEvent event) {
        for (IDownloadListener listener : downloadListeners) {
            listener.onDownloading(event);
        }
    }

    public synchronized void addListener(IDownloadListener downloadListener) {
        downloadListeners.add(downloadListener);
    }

    public synchronized void removeListener(IDownloadListener downloadListener) {
        downloadListeners.remove(downloadListener);
    }
}
